package com.jcl.recruit.console.user.mapper;

import com.jcl.recruit.console.user.model.SysUser;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @ClassName SysUserMapper
 * @Author yyliu
 * @Date 2018/12/18 10:51
 * @Version 1.0
 **/
public interface SysUserMapper {

    String TABLE_NAME = "t_sys_user";

    @Select({
            SQL_QUERY_ALL
    })
    List<SysUser> findList();

    @Select({
            SQL_QUERY_USERNAME
    })
    SysUser findOne(@Param("username") String username);

    @Select({
            SQL_QUERY_ID
    })
    SysUser findOneById(@Param("id") Integer id);

    @InsertProvider(type = SysUserSqlProvider.class, method = "insert")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(SysUser entity);

    @UpdateProvider(type = SysUserSqlProvider.class, method = "updateByPrimaryKey")
    int update(SysUser entity);

    @Update({
            SQL_UPDATE
    })
    int updatePw(@Param("id") Integer id, @Param("password") String password);

    @Update({
            SQL_DELETE
    })
    int delete(@Param("id") Integer id);

    String SQL_QUERY_ALL = "select * from " + TABLE_NAME;
    String SQL_QUERY_ID = "select * from " + TABLE_NAME + " where id = #{id}";
    String SQL_QUERY_USERNAME = "select * from " + TABLE_NAME + " where username = #{username}";
    String SQL_UPDATE = "update " + TABLE_NAME + " set password = #{password} where id = #{id}";
    String SQL_DELETE = "update " + TABLE_NAME + " set status = 1 where id = #{id}";
}
